﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;

namespace app_common
{
    public static class TPOS
    {
        public static Hashtable hashConfig = new Hashtable();
        public static Hashtable ReadPosConfig()
        {
            Hashtable result = new Hashtable();
            try
            {
                StreamReader sr = new StreamReader("tpos.conf");
                string text;
                while ((text = sr.ReadLine()) != null)
                {
                    if (text.IndexOf("[") >= 0)
                    {
                        continue;
                    }
                    if (text.Trim() == string.Empty)
                    {
                        continue;
                    }
                    string[] arr_text = text.Split(new Char[] { '=' });
                    if (!TPOS.hashConfig.ContainsKey(arr_text[0].Trim().ToLower()))
                        TPOS.hashConfig.Add(arr_text[0].Trim().ToLower(), arr_text[1].Trim());
                }
                sr.Close();
                result.Add(STATUS_MESSAGE.MESSAGE, STATUS_MESSAGE.SUCCESS);
                result.Add(STATUS_MESSAGE.VALUE, "Read config successfully");
            }
            catch (Exception ex)
            {
                result.Add(STATUS_MESSAGE.MESSAGE, STATUS_MESSAGE.ERROR);
                result.Add(STATUS_MESSAGE.VALUE, "Không thể đọc thông tin cấu hình POS.\n\rChi tiết:" + ex.Message);
            }
            return result;
        }
    }
}
